enum Gender {
	male,
	female
}

class Person {
	String name;
	Gender gender; 
	int age;
	Person children[];

	Person(String name, Gender gender, int age) {
		this.name = name;
		this.gender = gender;
		this.age = age;
	}

	Person(String name, Gender gender, int age, Person[] children) {
		this(name, gender, age);
		this.children = children;
	}
	
	String getName() {
		return name;
	}

	int getAge() {
		return age;
	}

	void increaseAge() {
		age++;
	}

	Person[] getChildren() {
		return children;
	} 

	void setChildren(Person[] children) {
		this.children = children;
	}

	void addChild(Person child) {
		if (children == null) {
			children = new Person[1];
		}
		else {
			// copyOf返回复制的数组
			// 新数组的大小由第二个参数指定
			children = java.util.Arrays.copyOf(children, children.length + 1); 

			// 更好的做法是用大小可变的容器，比如ArrayList
		}

		children[children.length - 1] = child;
	}

	public String toString() {
		String desc = "Name: " + name
			+ "\nGender: " + gender
			+ "\nAge: " + age;
		if (children != null)
			desc += "\nChildren numbers: " + children.length;

		return desc;
		
	}
}

class Main {
	public static void main(String[] args) {
		System.out.println("hello");

		Person tom = new Person("Tom", Gender.male, 43);

		Person marry = new Person("Marry", Gender.female, 10);
		Person tony = new Person("Tony", Gender.male, 3);

		tom.addChild(marry);
		tom.addChild(tony);
		

		System.out.println(tom);

		System.out.println("Tom's children:");
		
		for (Person child : tom.getChildren()) {
			System.out.println(child);
		}


		Person zhang3 = new Person("Zhang3", Gender.male, 40);
		Person childrenOfZhang3[] = {
				new Person("ZhangGG", Gender.male, 8), 
				new Person("ZhangMM", Gender.male, 6)
		}; 

		zhang3.setChildren(childrenOfZhang3);

		System.out.println(zhang3);

		System.out.println("Zhang3's children:");
		
		for (Person child : zhang3.getChildren()) {
			System.out.println(child);
		}


	}
}
